<template>
  <el-checkbox-group v-model="categoryValue">
    <el-checkbox
      v-for="(category, index) in category"
      :key="index"
      :label="category.id"
      :disabled="!index"
      >{{ category.title }}</el-checkbox
    >
  </el-checkbox-group>
</template>

<script>
import { packApi } from "@/utils/public";
import { order_splitCate, order_split } from "@/api/order/orderList";
export default {
  inject: ['getOrderList'],
  props: {
    orderId: {
      type: [String,Number],
      default: "",
    },
  },
  data() {
    return {
      category: [],
      categoryValue: [],
    }
  },
  methods: {
    getData() {
      order_splitCate(packApi({ id: this.orderId })).then(res=> {
        if(res.errcode == 0) {
          this.category = res.data.category;
        } else {
          this.$message.error(res.errmsg);
        }
      });
    },
    // 拆分订单
    split() {
      if(!this.categoryValue.length) return this.$message.error("请选择拆分分类");
      let data = {
        id: this.orderId,
        cate: JSON.stringify(this.categoryValue)
      };
      order_split(packApi(data)).then(res=> {
        if(res.errcode == 0) {
          if(this.getOrderList) this.getOrderList();
          this.$message.success("拆分成功");
          this.$emit("close");
        } else {
          this.$message.error(res.errmsg);
        }
      })
    },
    // 重置data数据
    resetData() {
      this.category = [];
      this.categoryValue = [];
    }
  }
}
</script>

<style lang="scss" scoped>
.el-checkbox-group {
  width: 1200px;
  margin-top: 25px;
  .el-checkbox {
    width: 150px;
    margin-bottom: 30px;
  }
}
</style>